package presenter;

import base.BasePresenter;
import bean.UserBean;
import model.LoginModel;
import model.LoginModelImpl;
import view.LoginView;

/**
 * Moral :
 * Created by 卖火柴的小女孩 on 2018/2/12.
 */

public class LoginPresenterImpl extends BasePresenter<LoginView> implements LoginPresenter {
    private LoginView loginView;
    private LoginModel loginModel;

    public LoginPresenterImpl(LoginView loginView) {
        this.loginView = loginView;
        this.loginModel = new LoginModelImpl();
    }

    @Override
    public void onLogin(String userName, String userPwd) {
        loginModel.login(userName, userPwd, new LoginModel.LoginOnListener() {
            @Override
            public void onSuccess(UserBean userBean) {
                if (isViewAttached())
                    loginView.onloginSuccess(userBean);
            }

            @Override
            public void onFail(String message) {
                if (isViewAttached())
                    loginView.onloginFail(message);
            }
        });
    }
}
